package cn.gok.yufa;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

/**
 * @ClassName 变量和常量
 * @Description TODO
 * @Author HP
 * @Date 10:56 2022/7/4
 * @Version 1.0
 **/
public class 变量和常量 {
    public static void main(String[] args) {
        //数值类();
        //字符类();
        //拆装箱();
        //字符串和其他类型的转换();
        字符();
    }

    private static void 字符() {
        //int i = "a";
        //System.out.println(i);
        for (int i = 0; i < 26; i++) {
            System.out.println();
        }
    }

    private static void 字符串和其他类型的转换() {
        int a = 123;
        //其他-->字符串
        String str = Integer.valueOf(a).toString();
        String str2 = new Integer(a).toString();
        //
        int a2 = Integer.parseInt(str);
        int a3 = new Integer("str2");
    }

    private static void 拆装箱() {
        int i = 10;
        Integer i2 = i;
        Integer i3 = new Integer(i);
        Integer i4 = Integer.valueOf(i);
        //拆箱
        int i5 = i2.intValue();
    }

    private static void 字符类() throws UnsupportedEncodingException {
        char c = 'a';
        char c2 = '\0';//空字符
        char c3 = ' ';//空格字符
        char c4 = '中';
        System.out.println(new String("中").getBytes("utf-8").length);
        //中文-->gbk编码2字节，utf-8 3个字节，unicode4个字节
    }

    private static void 数值类() {
        int i = Integer.MAX_VALUE;
        System.out.println(i);
        //int i2=12312344534534534;//报错
        long i2 = 123121432L;//采用L后缀，才是使用8个字节存储
        float f = (float) 10.0d;//10.0等价10.0d;多字节-->少字节，需要强制转换
    }
}
